home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / PNL010.ARJ / TEXTUTL2.PAS < prev   
Pascal/Delphi Source File  |  1992-03-01  |  3KB  |  104 lines

  1. Unit TextUtl2;  (* Version 1.0 *)
  2.  
  3. {Lets you use typed-file operators on TEXT files.  Note that I've cut out MOST}
  4. {of the documentation so as to make it more practical for the PNL.  I strongly}
  5. {advise that you get in touch with the author at the address below (I haven't)}
  6. {It's called TEXTUTL2 because it's a rewrite of an earlier unit called        }
  7. {TEXTUTIL which had some nasty limitations.                                   }
  8.  
  9. {Both files can be FREQed from 3:634/384.0 as TEXTUT*.*, and I strongly       }
  10. {recommend that you do so.                                                    }
  11.  
  12. {I tried looking up the author's telephone number, but Telecom says the number}
  13. {is silent.  Oh well.                                                         }
  14.  
  15. {If you're having trouble, netmail me (Mitch Davis) at 3:634/384.6            }
  16.  
  17.  
  18. (*
  19. Author: Rowan McKenzie  28/12/88
  20.         35 Moore Ave, Croydon, Vic, Australia
  21.  
  22. These 3 routines are improvements to Tim Baldock's TEXTUTIL.PAS unit.
  23. I can be contacted on: Eastwood, Amnet or Tardis BBS (Melbourne Australia)
  24. *)
  25.  
  26. Interface
  27.  
  28. Uses Dos;
  29.  
  30. Procedure TextSeek     (Var F : Text; Offset : Longint);
  31. Function  TextFileSize (Var F : Text): LongInt;
  32. Function  TextFilePos  (Var F : Text): LongInt;
  33.  
  34. Implementation
  35.  
  36. Procedure TextSeek(Var F : Text; Offset : Longint);
  37.  
  38. { seek char at position offset in text file f}
  39.  
  40. var BFile    : File of byte absolute F;  (* Set up File for Seek *)
  41.     BFileRec : FileRec absolute Bfile;
  42.     TFileRec : TextRec Absolute F;
  43.     OldRecSize : Word;
  44.     oldmode : word;
  45.  
  46. Begin
  47.   With BfileRec do Begin
  48.     oldmode:=mode;
  49.     Mode := FmInOut;         (* Change file mode so Turbo thinks it is *)
  50.     OldRecSize := RecSize;   (* dealing with a untyped file.           *)
  51.     RecSize := 1;            (* Set the Record size to 1 byte.         *)
  52.     Seek(Bfile,Offset);      (* Perform Seek on untyped file.          *)
  53.     Mode := oldmode;         (* Change file mode back to text so that  *)
  54.     RecSize := OldRecSize;   (* normal text operation can resume.      *)
  55.   end;
  56.   TfileRec.BufPos := TfileRec.BufEnd; (* Force next Readln.              *)
  57. end; {textseek}
  58.  
  59. Function TextFileSize(Var F : Text): LongInt;
  60.  
  61. { determine size of text file f in bytes}
  62.  
  63. var BFile:File of byte absolute F;
  64.     BFileRec:FileRec absolute Bfile;
  65.     OldRecSize:Word;
  66.     oldmode:word;
  67.  
  68. Begin
  69.   With BfileRec do Begin
  70.     oldmode:=mode;
  71.     Mode := FmInOut;
  72.     OldRecSize := RecSize;
  73.     RecSize := 1;
  74.     TextFileSize := FileSize(Bfile);
  75.     Mode := oldmode;
  76.     RecSize := OldRecSize;
  77.   end;
  78. end; {textfilesize}
  79.  
  80.  
  81. Function Textfilepos(Var F : Text): LongInt;
  82.  
  83. { determine current position (in bytes) in text file f}
  84.  
  85. var BFile:File of byte absolute F;
  86.     BFileRec:FileRec absolute Bfile;
  87.     TFileRec:TextRec Absolute F;
  88.     OldRecSize:Word;
  89.     oldmode:word;
  90.  
  91. Begin
  92.   With BfileRec do Begin
  93.     oldmode:=mode;
  94.     Mode := FmInOut;
  95.     OldRecSize := RecSize;
  96.     RecSize := 1;
  97.     textfilepos := Filepos(Bfile)-tfilerec.bufend+tfilerec.bufpos;
  98.     Mode := oldmode;
  99.     RecSize := OldRecSize;
  100.   end;
  101. end; {textfilepos}
  102.  
  103. end.
  104.